package com.example.demo.member.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.example.common.util.IdUtil;
import com.example.demo.member.model.Player;
import com.example.demo.member.service.PlayerService;

import io.seata.core.context.RootContext;

@RequestMapping("/player")
@RestController
public class PlayerController {

    @Autowired
    private PlayerService playerService;

    @RequestMapping("/list")
    public List<Player> list() {
        System.out.println("player list");
        List<Player> list = playerService.list();
        return list;
    }

    @PostMapping("/save")
    public void save(@RequestBody Player player) {
        String xid = RootContext.getXID();
        System.out.println("seata id: " + xid);

        player.setId(IdUtil.getId());
        playerService.save(player);
    }

}
